package com.ruoyi.purchase.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.domain.LogisticDetail;
import com.ruoyi.purchase.service.ILogisticDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * LogisticDetailController
 * 
 * @author kevinness
 * @date 2025-02-01
 */
@RestController
@RequestMapping("/LogisticDetail")
public class LogisticDetailController extends BaseController
{
    @Autowired
    private ILogisticDetailService logisticDetailService;

    /**
     * 查询LogisticDetail列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LogisticDetail logisticDetail)
    {
        startPage();
        List<LogisticDetail> list = logisticDetailService.selectLogisticDetailList(logisticDetail);
        return getDataTable(list);
    }

    /**
     * 根据订单编号获取物流详情
     */
    @PostMapping("/getListByOrderNo")
    public AjaxResult getListByOrderNo(@RequestBody String orderNo){
        return success(logisticDetailService.selectLogisticDetailByOrderNo(orderNo));
    }

    /**
     * 导出LogisticDetail列表
     */
    @Log(title = "LogisticDetail", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogisticDetail logisticDetail)
    {
        List<LogisticDetail> list = logisticDetailService.selectLogisticDetailList(logisticDetail);
        ExcelUtil<LogisticDetail> util = new ExcelUtil<LogisticDetail>(LogisticDetail.class);
        util.exportExcel(response, list, "LogisticDetail数据");
    }

    /**
     * 获取LogisticDetail详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(logisticDetailService.selectLogisticDetailById(id));
    }

    /**
     * 新增LogisticDetail
     */
    @Log(title = "LogisticDetail", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogisticDetail logisticDetail)
    {
        return toAjax(logisticDetailService.insertLogisticDetail(logisticDetail));
    }

    /**
     * 修改LogisticDetail
     */
    @Log(title = "LogisticDetail", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogisticDetail logisticDetail)
    {
        return toAjax(logisticDetailService.updateLogisticDetail(logisticDetail));
    }

    /**
     * 删除LogisticDetail
     */
    @Log(title = "LogisticDetail", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(logisticDetailService.deleteLogisticDetailByIds(ids));
    }
}
